package liurong.driver.jdk8;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class StreamTest implements B, C {
	public static void main(String[] args) {
		List<Person> personList = new ArrayList<Person>();

		personList.add(new Person("liurong", 12));
		personList.add(new Person("liurong1", 13));
		personList.add(new Person("liurong2", 14));
		personList.add(new Person("liurong3", 15));
		personList.add(new Person("liurong4", 16));

		// personList.forEach(new Consumer<Person>() {
		// @Override
		// public void accept(Person t) {
		// t.setAge(t.getAge() + 1);
		// }
		// });

		// 与上面是等价的
		personList.forEach((Person x) -> {
			x.setAge(x.getAge() + 1);
		});

		List<Integer> ageList = personList.stream().sorted().map(Person::getAge).collect(Collectors.toList());
		List<String> nameList = personList.stream().map(Person::getName).collect(Collectors.toList());
		System.out.println(ageList);
		System.out.println(nameList);

		// 定义方法
		test((x) -> {
			x.setAge(1);
			System.out.println(x);
		});
	}

	public static void test(TestInte testInte) {
		testInte.fun1(new Person());
	}

	@Override
	public void run() {

	}

	@Override
	public void sleep() {
		C.super.sleep();
	}
}

interface B {
	void run();

	default public void sleep() {
		System.out.println("sleep");
	}
}

interface C {
	default public void sleep() {
		System.out.println("sleep c");
	}
}

@FunctionalInterface
interface TestInte {
	void fun1(Person person);
}
